package spring;

import spring.service.MyService;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.remoting.rmi.RmiServiceExporter;

/**
 * @Description
 * @Author tuyou_cd
 * @Date 2020/6/19 16:03
 */
@Configuration
public class SpringRMIServerApp {

    @Profile("server")
    @Bean
    public RmiServiceExporter rmiServiceExporter(MyService myService) {
        RmiServiceExporter exporter = new RmiServiceExporter();
        exporter.setServiceName("myService");
        exporter.setService(myService);
        exporter.setServiceInterface(MyService.class);
        exporter.setRegistryPort(9999);
//        exporter.setRegistryHost("127.0.0.1");
        return exporter;
    }

    public static void main(String[] args) {

        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
        applicationContext.getEnvironment().addActiveProfile("server");
        applicationContext.scan("me.tuyou");
        applicationContext.refresh();

        System.out.println("server ready");
    }
}
